package com.my.mymafengwo.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.smallstrong.mafengwopro.R;

import java.util.ArrayList;
import java.util.List;

/**
 * ***********************************************
 * author:ljz
 * time:2015/12/4 14:4
 * name:找攻略页面ListView所使用的适配器
 * step:
 * ***********************************************
 */
    public  class ContinentsAdapter extends BaseAdapter {
    private Context context;
    private List<String> data;//数据
    private List<TextView> list;
    private List<ImageView> listImage;
    public ContinentsAdapter(Context context){
        this.context=context;
        list=new ArrayList<>();
        listImage=new ArrayList<>();
    }
    public void setData(List<String> data) {
        this.data = data;
    }
    public List<TextView> getTextView(){
        return list;
    }
    public List<ImageView> getImageView(){
        return listImage;
    }
    @Override
        public int getCount() {
        return data == null ? 0 : data.size();
        }

        @Override
        public Object getItem(int position) {
            return data.get(position);
        }

        @Override
        public long getItemId(int position) {
            return position;
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ViewHolder holder;
            if(convertView == null) {
                convertView = View.inflate(context, R.layout.item_continents, null);
                holder = new ViewHolder();
                holder.tv = (TextView) convertView.findViewById(R.id.tv_hot);
                holder.iv= (ImageView) convertView.findViewById(R.id.iv_navigator);
                list.add( holder.tv);
                listImage.add(holder.iv);
                convertView.setTag(holder);
            } else {
                holder = (ViewHolder) convertView.getTag();
            }
            holder.tv.setText(data.get(position));
            if(position==0){
                holder.tv.setTextColor(context.getResources().getColor(R.color.orange));
                holder.iv.setVisibility(View.VISIBLE);
            }else{
                holder.tv.setTextColor(context.getResources().getColor(R.color.black));
                holder.iv.setVisibility(View.INVISIBLE);
            }
            return convertView;
        }

        class ViewHolder {
            TextView tv;
            ImageView iv;
        }
    }